<?php
/* @var $this SiteController */
$this->pageTitle=Yii::app()->name;

?>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">         
        <script type="text/javascript" src="<?php echo Yii::app()->baseUrl ?>/assets/js/jquery-1.7.2.min.js"></script>
        <script type="text/javascript" src="<?php echo Yii::app()->baseUrl ?>/assets/js/jquery-ui-1.10.3.min.js"></script>
        <!--ckeditor-->
<!--        <script type="text/javascript" src="<?php echo Yii::app()->baseUrl ?>/ckeditor/ckeditor.js"></script>
        <script type="text/javascript" src="<?php echo Yii::app()->baseUrl ?>/ckeditor/config.js"></script>-->
        
        <!--elFinder CSS (REQUIRED)--> 
        <link rel="stylesheet" type="text/css" media="screen" href="<?php echo Yii::app()->baseUrl ?>/css/elfinder.min.css">
        <link rel="stylesheet" type="text/css" media="screen" href="<?php echo Yii::app()->baseUrl ?>/css/theme.css">
        
        <!--elFinder JS (REQUIRED)--> 
        <script type="text/javascript" src="<?php echo Yii::app()->baseUrl ?>/js/elfinder.min.js"></script>
        
        <!--elFinder translation (OPTIONAL)--> 
        <script type="text/javascript" src="<?php echo Yii::app()->baseUrl ?>/js/i18n/elfinder.ru.js"></script>
        
        <!--elFinder initialization (REQUIRED)--> 
        <script type="text/javascript" charset="utf-8">
            $().ready(function() {
            });
        </script>
        <link href="<?php echo Yii::app()->baseUrl."css/form.css"?>"rel="stylesheet"/>
        <title></title>
    </head>
    <body>
        <?php
         try{
                $connection=Yii::app()->db;   // assuming you have configured a "db" connection
                $query="SELECT *  FROM os_category
                    WHERE os_category.sale_id =".Yii::app()->session["saleId"];
                $command=$connection->createCommand($query);
                $dataReader=$command->query();
                $rows_category = array();

                while(($row=$dataReader->read())!==false) {
                    $rows_category[]=$row;
                }
//                $string=json_encode($rows_store);
//                echo $string;
            }catch(Exception $e){
                $result=array('data'=>'','status'=>'fail','error'=>$e->getMessage());
                 echo $string=json_encode($result);
             }        
        ?>
        <div id="main-container" class="main-container">
            <div id="breadcrumbs" class="breadcrumbs">
                <script type="text/javascript">
                    try{ace.settings.check('breadcrumbs' , 'fixed')}catch(e){};
                </script>
                <ul class="breadcrumb">
                    <li>
                        <i class="icon-home home-icon"></i>
                        <a href="../site/index"><strong>Trang Chủ</strong></a>
                    </li>
                    <li>
                        <a href="../site/item"><strong>Sản Phẩm</strong></a>
                    </li>                                                                                                                                       
                    <li>
                        <strong> Thêm Sản Phẩm </strong>
                    </li>
                </ul><!-- .breadcrumb -->
                
                <div id="nav-search" class="nav-search">
                    <form class="form-search">
                        <span class="input-icon">
                            <input type="text" autocomplete="off" id="nav-search-input" class="nav-search-input" placeholder="Search ...">
                            <i class="icon-search nav-search-icon"></i>
                        </span>
                    </form>
                </div><!-- #nav-search -->
            </div>    
            
            <div class="page-content">
                <div class="page-header">
                    <h1><strong>Thêm Sản Phẩm</strong></h1>
                </div><!-- /.page-header -->
                <div class="row">
                    <div class="col-xs-12">
            <?php $form=$this->beginWidget('CActiveForm', array(
                'htmlOptions' => array(
                    'enctype' => 'multipart/form-data',
                ),              
            ));?>
                        <!--<form class="form-horizontal" method="POST" enctype="multipart/form-data">-->
                        <fieldset>
                            <div class="form-group">
                        <?php // echo $form->error($model,'name');?>
                                <label class="col-sm-2 control-label no-padding-right">
                                    Tên Sản Phẩm
                                </label>
                                <div class="col-sm-10">
                                    <input class="col-xs-10 col-sm-5" type="text" name="ItemForm[name]" id="ItemForm_name" value="New Item"></input>
                                </div>
                            </div>
                            <div class="clearfix"></div>
                            <div class="space-6"></div>
                            
                            <div class="form-group">
                        <?php // echo $form->error($model,'name');?>
                                <label class="col-sm-2 control-label no-padding-right">
                                    Nhóm Sản Phẩm
                                </label>
                                <div class="col-sm-10">
                                    <select class="col-xs-10 col-sm-5" name="ItemForm[IdCategory]" id="ItemForm_IdCategory">
                                        <option value="">-- Chọn một Nhóm Sản Phẩm --</option>
                        <?php
                        foreach($rows_category as $key => $value):
                        echo "<option value={$value['Id']}>{$value['NameCategory']}</option>"; //close your tags!!
                        endforeach;
                        ?>
                                    </select>
                                        <!--<input class="col-xs-10 col-sm-5" type="text" name="ItemForm[namecategory]" id="ItemForm_namecategory" value="New Category"></input>-->
                                </div>
                            </div>
                            <div class="clearfix"></div>
                            <div class="space-6"></div>
                            
                            <div class="form-group">
                        <?php // echo $form->error($model,'name');?>
                                <label class="col-sm-2 control-label no-padding-right">
                                    Giá Sản Phẩm
                                </label>
                                <div class="col-sm-10">
                                    <input class="col-xs-10 col-sm-5" type="number" name="ItemForm[price]" id="ItemForm_price"></input>
                                </div>
                            </div>
                            <div class="clearfix"></div>
                            <div class="space-6"></div>
                            
                            <div class="form-group">
                                <label class="col-sm-2 control-label no-padding-right">
                                    Thông Tin Chi Tiết
                                </label>
                                <div class="col-sm-10">
                                    <textarea class="col-xs-10 col-sm-5" cols="20" rows="5" name="ItemForm[description]" id="ItemForm_description"></textarea>
                                    <!--<input class="col-xs-10 col-sm-5" type="text" name="NewsForm[content]" id="NewsForm_content"></input>-->
                                </div>
                            </div>
                            <div class="clearfix"></div>
                            <div class="space-6"></div>
                            
                            <div class="form-group"> 
                                <label class="col-sm-2 control-label no-padding-right">
                                    Ảnh chính
                                </label>
                                <div class="col-sm-10" >
                            <?php // echo CHtml::activeFileField($model, 'image'); ?>
                                    <img src="../../images/photo.png" onclick="imageClick();" id="LinkImage" name="LinkImage" style="max-height: 600px; max-width: 800px;"/>
                                    <input type="hidden" id="ItemForm_image" name="ItemForm[image]" type="text"/>
                                    
                                    <p class="help-block">                                
                                        Image must be more than 100x100px and smaller than 3MB
                                    </p>
                                </div>
                            </div>
                            <div class="clearfix"></div>
                            <div class="space-6"></div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label no-padding-right">
                                    Ảnh phụ
                                </label>
                                <div class="col-sm-10">
                                    <div class="col-xs-10 col-sm-5">                                      
                                        <input multiple="true" type="file" id="id-input-file" name="ItemForm[]"/>   
                                        <p class="help-block">                                
                                        Image must be more than 100x100px and smaller than 2MB
                                    </p>
                                    </div>
                                    <div class="col-xs-10 col-sm-5" style="color: red">
                                        <?php echo $form->error($model,'sub_image');?>
                                    </div>
                                </div>
                            </div>
                            <div class="clearfix"></div>
                            <div class="space-6"></div>
                            <div class="form-group">
                        <?php // echo $form->error($model,'name');?>
                                <label class="col-sm-2 control-label no-padding-right">
                                    Giảm Giá
                                </label>
                                <div class="col-sm-10">
                                    <input class="col-xs-10 col-sm-5" type="number" name="ItemForm[discount]" id="ItemForm_discount" value="0"></input>
                                </div>
                            </div>
                            <div class="clearfix"></div>
                            <div class="space-6"></div>
                            
                            <div class="form-group">
                        <?php // echo $form->error($model,'name');?>
                                <label class="col-sm-2 control-label no-padding-right">
                                    Đơn Vị Tính
                                </label>
                                <div class="col-sm-10">
                                    <input class="col-xs-10 col-sm-5" type="text" name="ItemForm[unit]" id="ItemForm_unit" value="VND"></input>
                                </div>
                            </div>
                            <div class="clearfix"></div>
                            <div class="space-6"></div>
                            <div class="form-group">
                        <?php // echo $form->error($model,'name');?>
                                <label class="col-sm-2 control-label no-padding-right">  
                                    Đăng lên tường facebook
                                </label>
                                <div class="col-sm-10">
                                    <!--<label class="inline">-->
                                    <!--<input type="checkbox" class="ace" id="ItemForm_checkfb" name="ItemForm[checkfb]" value="1"/>-->
                                    <!--                <span class="lbl"> Đăng lên tường nhà bạn</span>
                                   </label> -->
                     <?php 
                                $this->widget('ext.SocialShareButton.SocialShareButton', array(
                                'style'=>'horizontal',
                        //            'style'=>'vertical',
                                'networks' => array('facebook'
                        //            ,'googleplus','linkedin','twitter'
                                    ),
                                'data_via'=>'', //twitter username (for twitter only, if exists else leave empty)
                        )); ?>
                                    
                                    
                                </div>
                            </div>
                            <div class=" clearfix"></div>
                            <div class="clearfix form-actions">
                                <div class="col-md-offset-2 col-md-10">
                                    <!--<a class="btn btn-sm btn-primary" type="button" id="submit" name="submit" value="submit">-->
                                    <!--<a class="btn btn-sm btn-primary" type="button" name="submit" value="submit" onclick="post_on_wall();">-->
                                    <button class="btn btn-sm btn-primary" type="submit" id="submit" name="submit" value="submit">
                                        <i class="icon-save align-top bigger-125"></i>
                                        Save
                                    </button>
                                    <!--</a>-->  
                                    <a class="btn btn-sm" type="button" href="../site/item">        
                                       <!--   <?php // echo Yii::app()->createAbsoluteUrl("/site/item"); ?> <=> "../site/item"-->
                                        Back
                                        <i class="icon-backward align-top bigger-125"></i>
                                    </a>
                                </div>
                            </div>
                        </fieldset>
                        <!--</form>-->
            <?php $this->endWidget(); ?>
                    </div>
                </div>
                
            </div>
        </div>
        <script type="text/javascript">
            window.jQuery || document.write("<script src='<?php echo Yii::app()->baseUrl."/assets/js/jquery-2.0.3.min.js"?>'>"+"<"+"/script>");
        </script>
        <script type="text/javascript">
            if("ontouchend" in document) document.write("<script src='<?php echo Yii::app()->baseUrl."/assets/js/jquery.mobile.custom.min.js"?>'>"+"<"+"/script>");
        </script>
        <script src="<?php echo Yii::app()->baseUrl."/assets/js/bootstrap.min.js" ?>"></script>
        <script src="<?php echo Yii::app()->baseUrl."/assets/js/typeahead-bs2.min.js"?>"></script>
        <!-- ace scripts -->
        <script src="<?php echo Yii::app()->baseUrl."/assets/js/ace-elements.min.js"?>"></script>
        <script src="<?php echo Yii::app()->baseUrl."/assets/js/ace.min.js"?>"></script>
        <script type="text/javascript" charset="utf-8">
            jQuery(function($) {
                $('#id-input-file').ace_file_input({
                    style:'well',
                    btn_choose:'Drop files here or click to choose',
                    btn_change:null,
                    no_icon:'icon-cloud-upload',
                    droppable:true,
                    thumbnail:'small'//large | fit
                    //,icon_remove:null//set null, to hide remove/reset button
                    /**,before_change:function(files, dropped) {
                                                //Check an example below
                                                //or examples/file-upload.html
                                                return true;
                                        }*/
                    /**,before_remove : function() {
                                                return true;
                                        }*/
                    ,
                    preview_error : function(filename, error_code) {                
                        //name of the file that failed
                        //error_code values
                        //1 = 'FILE_LOAD_FAILED',
                        //2 = 'IMAGE_LOAD_FAILED',
                        //3 = 'THUMBNAIL_FAILED'
                        //alert(error_code);
                    }
			
                }).on('change', function(){
                    //console.log($(this).data('ace_input_files'));
                    //console.log($(this).data('ace_input_method'));
                });
            });
            function imageClick(){
                $( "#dialog-message" ).dialog({
                    title:"",
                    height:600,
                    width:1100,
                    modal: true
                });					
                var elf = $('#elfinder').elfinder({
                    url : '<?php echo Yii::app()->baseUrl ?>/php/connector.php' // connector URL (REQUIRED)
                    ,lang: 'en',
                    width:'100%',
                    commandsOptions: {
                        getfile: {
                            oncomplete: 'destroy' 
                        }
                    },
                    getFileCallback: function(file) {
                        $('#LinkImage').attr('src',file);
                        //                       $('#CategoryForm_image').attr('value',file);
                        //                            $('#CategoryForm_image').attr('src',file);
                        $('#ItemForm_image').attr('value',file);
                        $( "#dialog-message" ).dialog( "close" );
                    }
                }).elfinder('instance'); 
                
            };
 
            // window.fbAsyncInit = function()
            //{
            //    FB.init({
            //        appId  : '1429736400634740',
            //        status : true, // check login status
            //        cookie : true, // enable cookies to allow the server to access the session
            //        xfbml  : true , // parse XFBML
            //        oauth : true, // Enable oauth authentication
            //    });
            //};
            //function post_on_wall(){
            ////    if ($("#checkfb").is(':checked')) {
            ////    if(document.getElementById("checkfb").checked) {
            //    FB.login(function(response) {
            //        if (response.authResponse) {
            ////            alert('Logged in!');
            //            // Post message to your wall
            //            //api fb
            //FB.api('/me/links',
            //    'POST', {
            //        'link': 'http://localhost/orderservice/index.php/site/item',
            //        'picture': '<?php echo Yii::app()->baseUrl ?>/images/photo.png',
            ////        "name": "My test App",
            ////        "caption": "My site",
            ////        "description" : "Testing",
            //        'message': document.getElementById('ItemForm_name').value,   
            //    }, function(response) {
            //  if (!response || response.error) {
            //    alert(JSON.stringify(response.error));
            //  } else {
            //    alert('Đăng lên tường thành công!');
            ////   e.preventDefault(); //will stop the link href to call the blog page
            //   setTimeout(function () {
            //       window.location.href = '../site/item'; //will redirect to your blog page (an ex: blog.html)
            //    }, 0); //will call the function after 0 secs.
            //  }
            //});
            //        }
            //        else {
            //            alert('Not logged in');
            //        }
            //    }  ,
            //    { scope : 'publish_stream' }
            //);
            //}
        </script>
        <div id="dialog-message" >
            <div id="elfinder"></div>
        </div>
        <!--<div id="fb-root"></div>
        <script type="text/javascript" charset="utf-8">
        (function() {
            var e = document.createElement('script');
            // replacing with an older version until FB fixes the cancel-login bug
            e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
            //e.src = 'scripts/all.js';
            e.async = true;
            document.getElementById('fb-root').appendChild(e);
        }());
        </script>-->
    </body>
</html>
